package com.itboy.mall.pms.attrattrgroup.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.itboy.common.annotation.RepeatSubmit;
import com.itboy.common.annotation.Log;
import com.itboy.common.core.controller.BaseController;
import com.itboy.common.core.domain.AjaxResult;
import com.itboy.common.enums.BusinessType;
import com.itboy.mall.pms.attrattrgroup.vo.MallAttrAttrGroupVo;
import com.itboy.mall.pms.attrattrgroup.bo.MallAttrAttrGroupQueryBo;
import com.itboy.mall.pms.attrattrgroup.bo.MallAttrAttrGroupAddBo;
import com.itboy.mall.pms.attrattrgroup.bo.MallAttrAttrGroupEditBo;
import com.itboy.mall.pms.attrattrgroup.service.IMallAttrAttrGroupService;
import com.itboy.common.utils.poi.ExcelUtil;
import com.itboy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 属性&属性分组关联Controller
 *
 * @author itboy
 * @date 2021-07-24
 */
@Api(value = "属性&属性分组关联控制器", tags = {"属性&属性分组关联管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mall/attrAttrGroup")
public class MallAttrAttrGroupController extends BaseController {

    private final IMallAttrAttrGroupService iMallAttrAttrgroupService;

    /**
     * 查询属性&属性分组关联列表
     */
    @ApiOperation("查询属性&属性分组关联列表")
    @GetMapping("/listByAttrId")
    public TableDataInfo<MallAttrAttrGroupVo> list(@Validated MallAttrAttrGroupQueryBo bo) {
        return iMallAttrAttrgroupService.queryPageList(bo);
    }

    /**
     * 导出属性&属性分组关联列表
     */
    @ApiOperation("导出属性&属性分组关联列表")
    @PreAuthorize("@ss.hasPermi('mall:attrAttrGroup:export')")
    @Log(title = "属性&属性分组关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MallAttrAttrGroupVo> export(@Validated MallAttrAttrGroupQueryBo bo) {
        List<MallAttrAttrGroupVo> list = iMallAttrAttrgroupService.queryList(bo);
        ExcelUtil<MallAttrAttrGroupVo> util = new ExcelUtil<MallAttrAttrGroupVo>(MallAttrAttrGroupVo.class);
        return util.exportExcel(list, "属性&属性分组关联");
    }

    /**
     * 获取属性&属性分组关联详细信息
     */
    @ApiOperation("获取属性&属性分组关联详细信息")
    @PreAuthorize("@ss.hasPermi('mall:attrAttrGroup:query')")
    @GetMapping("/{id}")
    public AjaxResult<MallAttrAttrGroupVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iMallAttrAttrgroupService.queryById(id));
    }

    /**
     * 新增属性&属性分组关联
     */
    @ApiOperation("新增属性&属性分组关联")
    @PreAuthorize("@ss.hasPermi('mall:attrAttrGroup:add')")
    @Log(title = "属性&属性分组关联", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody MallAttrAttrGroupAddBo bo) {
        return toAjax(iMallAttrAttrgroupService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改属性&属性分组关联
     */
    @ApiOperation("修改属性&属性分组关联")
    @PreAuthorize("@ss.hasPermi('mall:attrAttrGroup:edit')")
    @Log(title = "属性&属性分组关联", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody MallAttrAttrGroupEditBo bo) {
        return toAjax(iMallAttrAttrgroupService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除属性&属性分组关联
     */
    @ApiOperation("删除属性&属性分组关联")
    @Log(title = "属性&属性分组关联" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iMallAttrAttrgroupService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
